//
// Created by Zxy on 2020/8/16.
//
#ifndef QUICK_SORT_SORTHELPER_H
#define QUICK_SORT_SORTHELPER_H

#include <iostream>
#include <cassert>
#include <ctime>
using namespace std;
// 产生随机数组
// 生成有n个元素的随机数组,每个元素的随机范围为[rangeL, rangeR]
int *generateRandomArray(int n, int rangeL, int rangeR) {

    assert(rangeL <= rangeR);

    int *arr = new int[n];

    srand(time(NULL));
    for (int i = 0; i < n; i++)
        arr[i] = rand() % (rangeR - rangeL + 1) + rangeL;
    return arr;
}
// 产生近乎有序的数组
int *generateNearlyOrderedArray(int n, int swapTimes){

    int *arr = new int[n];
    for(int i = 0 ; i < n ; i ++ )
        arr[i] = i;

    srand(time(NULL));
    for( int i = 0 ; i < swapTimes ; i ++ ){
        int posx = rand()%n;
        int posy = rand()%n;
        swap( arr[posx] , arr[posy] );
    }

    return arr;
}

// 打印数组
template<typename T>
void printArray(T arr[], int n) {

    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;

    return;
}

// 复制整型数组
int *copyIntArray(int a[], int n){

    int *arr = new int[n];
    copy(a, a+n, arr);
    return arr;
}

// 测试时间
template<typename T>
void testSort(const string &sortName, void (*sort)(T[], int), T arr[], int n) {

    clock_t startTime = clock();
    sort(arr, n);
    clock_t endTime = clock();
    cout << sortName << " : " << double(endTime - startTime) / CLOCKS_PER_SEC << " s"<<endl;

    return;
}

#endif //QUICK_SORT_SORTHELPER_H
